package com.ruoyi.system.controller;

import java.util.HashSet;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ExamPackage;
import com.ruoyi.system.service.IExamPackageService;
import com.ruoyi.system.service.IExamProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Examintions;
import com.ruoyi.system.service.IExamintionsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 项目体检Controller
 * 
 * @author ruoyi
 * @date 2025-05-09
 */
@RestController
@RequestMapping("/examintions")
public class ExamintionsController extends BaseController
{
    @Autowired
    private IExamintionsService examintionsService;
    @Autowired
    private IExamPackageService iExamPackageService;

    /**
     * 查询项目体检列表
     */
    @RequiresPermissions("system:examintions:list")
    @GetMapping("/list")
    public TableDataInfo list(Examintions examintions)
    {
        startPage();
        List<Examintions> list = examintionsService.selectExamintionsList(examintions);
        for (Examintions examintions1 : list) {
            ExamPackage examPackages = iExamPackageService.selectExamPackageById(examintions1.getPoType());
            examintions1.setPoName(examPackages.getPackageName());
        }
        return getDataTable(list);
    }

    /**
     * 导出项目体检列表
     */
    @RequiresPermissions("system:examintions:export")
    @Log(title = "项目体检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Examintions examintions)
    {
        List<Examintions> list = examintionsService.selectExamintionsList(examintions);
        ExcelUtil<Examintions> util = new ExcelUtil<Examintions>(Examintions.class);
        util.exportExcel(response, list, "项目体检数据");
    }

    /**
     * 获取项目体检详细信息
     */
    @RequiresPermissions("system:examintions:query")
    @GetMapping(value = "/{exId}")
    public AjaxResult getInfo(@PathVariable("exId") Integer exId)
    {
        return success(examintionsService.selectExamintionsByExId(exId));
    }

    /**
     * 新增项目体检
     */
    @RequiresPermissions("system:examintions:add")
    @Log(title = "项目体检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Examintions examintions)
    {
        return toAjax(examintionsService.insertExamintions(examintions));
    }

    /**
     * 修改项目体检
     */
    @RequiresPermissions("system:examintions:edit")
    @Log(title = "项目体检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Examintions examintions)
    {
        return toAjax(examintionsService.updateExamintions(examintions));
    }

    /**
     * 删除项目体检
     */
    @RequiresPermissions("system:examintions:remove")
    @Log(title = "项目体检", businessType = BusinessType.DELETE)
	@DeleteMapping("/{exIds}")
    public AjaxResult remove(@PathVariable Integer[] exIds)
    {
        return toAjax(examintionsService.deleteExamintionsByExIds(exIds));
    }

    @RequestMapping("getExamintionsProjectName")
    public AjaxResult getExamintionsProjectName(){
        List<Examintions> examintionsProjectName = examintionsService.getExamintionsProjectName();
        return success(examintionsProjectName);
    }
}
